﻿using System;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;

namespace MapEditor
{
    public class Chooser
    {
        Texture2D texture;
        Vector2 position;

        public Vector2 Position
        {
            get
            {
                return position;
            }
            set
            {
                position = value;
            }
        }

        KeyboardState keyboardstate;
        KeyboardState last_keyboardstate;

        public Chooser()
        {
            position = Vector2.Zero;
        }

        public void LoadContent(ContentManager Content)
        {
            texture = Content.Load<Texture2D>("image/chooser");
        }

        public void Update(GameTime gameTime, Vector2 mapSize)
        {
            last_keyboardstate = keyboardstate;
            keyboardstate = Keyboard.GetState();

            if (keyboardstate.IsKeyDown(Keys.Left) && last_keyboardstate.IsKeyUp(Keys.Left) && position.X > 0)
                position.X--;
            if (keyboardstate.IsKeyDown(Keys.Right) && last_keyboardstate.IsKeyUp(Keys.Right) && position.X < mapSize.X - 1)
                position.X++;
            if (keyboardstate.IsKeyDown(Keys.Up) && last_keyboardstate.IsKeyUp(Keys.Up) && position.Y > 0)
                position.Y--;
            if (keyboardstate.IsKeyDown(Keys.Down) && last_keyboardstate.IsKeyUp(Keys.Down) && position.Y < mapSize.Y - 1)
                position.Y++;
        }

        public void Draw(SpriteBatch spritebatch)
        {
            spritebatch.Draw(texture, new Vector2(position.X * texture.Width, position.Y * texture.Height), Color.White);
        }
    }
}
